package com.bobby.service.impl;

import com.bobby.dao.UserDao;
import com.bobby.dao.impl.UserDaoImpl;
import com.bobby.pojo.User;
import com.bobby.service.UserService;

import java.sql.SQLException;

/**
 * @Description TODO
 * @Date 2020/8/13 11:01
 * @Created wenjunpei
 */
public class UserServiceImpl implements UserService {

    private UserDao userDao = new UserDaoImpl();

    @Override
    public void registerUser(User user) throws SQLException {
        userDao.saveUser(user);
    }

    @Override
    public User login(User user) throws SQLException {
        return userDao.queryUserByUsernameAndPassword(user.getUsername(),user.getPassword());
    }

    @Override
    public boolean existsUsername(String username) throws SQLException {
        User user = userDao.queryUserByUsername(username);
        return user != null ? true : false;
    }
}
